package com.hspedu.encap;

public class test {
    public static void main(String[] args) {
        person person = new person();
        person.setName("jack");
        person.setAge(132);
        person.setSalary(10000);
        System.out.println(person.info());
        person p1 = new person("smith",233,150000);
        System.out.println(p1.info());
    }
}

class person {
    public String name;//名字公开
    private int age;//年龄私有
    private double salary;//..

    public person() {
    }

    public person(String name, int age, double salary) {
//        this.name = name;
//        this.age = age;
//        this.salary = salary;
        setSalary(salary);
        setAge(age);
        setName(name);
    }

    public String getName() {

        return name;
    }

    public void setName(String name) {
        if (name.length() >= 2 && name.length() <= 6) {
            this.name = name;
        }
        else {
            System.out.println("名字需要在(2-6个字符之间)!!");
            this.name = "null";
        }
    }

    public int getAge() {

        return age;
    }

    public void setAge(int age) {
        if (age >= 1 && age <= 120) {
            this.age = age;
        } else {
            System.out.println("年龄设置范围(1-120)!!");
            this.age = 18;
        }
    }

    public double getSalary() {

        return salary;
    }

    public void setSalary(double salary) {

        this.salary = salary;
    }

    public String info() {
        return "name=" + name +  "年龄=" + age + "薪水=" + salary;
    }
}
